package com.motorola.dp.jenkinsmonitor.service.util.properties;

import java.util.Properties;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.motorola.dp.jenkinsmonitor.model.util.exception.PropertyReadException;

@Service("applicationPropertiesService")
public class DefaultPropertiesService implements PropertiesService {

    @Resource(name = "applicationProperties")
    private Properties properties;

    public String getString(String propertyName) {
        return properties.getProperty(propertyName);
    }

    public Integer getInteger(String propertyName) {
        String propString = properties.getProperty(propertyName);
        try {
            return Integer.parseInt(propString);
        } catch (NumberFormatException e) {
            throw new PropertyReadException("could not read property " + propertyName, e);
        }
    }

    public Boolean getBoolean(String propertyName) {
        String propString = properties.getProperty(propertyName);
        return Boolean.parseBoolean(propString);
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
    }

}
